home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13226 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  61 lines

  1. Path: EU.net!sun4nl!xs4all!usenet
  2. From: martijnl@xs4all.nl (Martijn Lievaart)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Dynamically initializing static members
  5. Date: Sun, 24 Mar 1996 11:17:47 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4j3b1d$n3v@news.xs4all.nl>
  8. References: <4ituc6$c1h@rc1.vub.ac.be>
  9. NNTP-Posting-Host: mas01-09.dial.xs4all.nl
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. class MYCLASS {
  13.   static unsigned int Registration_ID
  14.  
  15.   ...
  16.  
  17. }
  18. unsigned int MYCLASS::Registration_D = Registrate("MYCLASS");
  19.  
  20. should do the trick (you where almost there!).
  21.  
  22. apardon@rc1.vub.ac.be (Antoon Pardon) wrote:
  23.  
  24. >I am playing with the idea of somekind of classregistration.
  25.  
  26. >The registration class would provide for a function: 
  27.  
  28. >unsigned int Registrate(const char *name);
  29.  
  30. >This would keep the name of the function stored somewhere and
  31. >would return a registration ID.
  32.  
  33. >The idea would be to include a static int into the class that
  34. >would store this ID something like this
  35.  
  36. >class MYCLASS {
  37. >  static unsigned int
  38. >    Registration_ID
  39.  
  40. >  ...
  41.  
  42. >}
  43.  
  44. >The problem now is how do I assign this Registration_ID
  45. >automatically. In Modula 2 you have initialisation code
  46. >that is called at the start of the program where you might
  47. >then put code similar to 
  48.  
  49. >MYCLASS::Registration_D = Registrate("MYCLASS");
  50.  
  51. >Is something similar possible in C++ or do I have to
  52. >do it in a different way? I looked at the FAQ but
  53. >couldn't find an answer there.
  54.  
  55.  
  56.      /~~~~~| /~~~~~| /~~~~~~|~~~~~\~~~~~\~~~~|~~~~~|   We now return to our
  57.     /      |/      |/       |   o  |  o  |  |   +-|     regularly scheduled
  58.    /   /|     /|   |   /|   |  ___/  ___/   |   +-|          flame-throwing
  59. ../___/.|____/.|___|__/~|___|_|..|__|..|_____|_____|...martijnl@xs4all.nl..
  60.  
  61.